
export default {
  data() {
    return {
      isShow: true,
      setTime: '',
      type: 0,//（0、支付宝 1、微信 2、余额）
      id: '',
      msg: {},
      fail: false,
      failmsg: '',
      ordertype: '',//（0、合同订单 1、商品订单 2、保证金）
    }
  },
  onLoad(option) {
    // this.contractid = option.contractid
    this.ordertype=option.paytype
    // this.ordertype=0
    console.log(option)
    this.type=option.type //支付方式
    this.id=option.id //
    this.getPageData()
    console.log(option)
  },
  //  监听返回按钮 记得return true
  onBackPress(options) {
	  if(options.from==='backbutton'){
      this.getUserInfo()
	    uni.switchTab({
			  url: '/pages/index/index'
	    })

	    return true
	  }
  },
  created() {
	  // 查询是否支付成功，轮询接口，知道接口信息返回true
	  this.t = setInterval(() => {
	    this.getPageData()
	  }, 1500)
  },
  methods: {
    getPageData() {
      uni.showLoading()
      var req = {}
      if(this.ordertype==0){
        req = {
				  contractid: this.id,
          ordertype: this.ordertype,
          storeid: ''
        }
      }else{
        req = {
          storeid: this.id,
          ordertype: this.ordertype,
        }
      }

      console.log('支付参数',req)
				 this.$api.pay.PaySucceedDataListTask(req).then(res => {
        console.log(res)
        this.msg=res.data.list[0]
        clearInterval(this.t)
        uni.hideLoading()
      }).catch(err => {
        clearInterval(this.t)
        uni.hideLoading()
        console.log(err)
        this.fail=true
        this.failmsg='支付失败，请稍后再试'
      })

    },
    goOrderList(){
      console.log(111)
      if(this.ordertype==0){
        uni.redirectTo({
				    url: '/pages_order/orderAdmin/orderAdmin'
        })
      }else{
		   this.getUserInfo()
        console.log(222)

      }

    },
    //获取用户信息

    async getUserInfo() {

      // let userInfo= uni.getStorageSync('userInfoDetail')
      // userInfo.store.isPay=false
      // uni.setStorageSync('userInfoDetail',userInfo)
		  try{
		    const res = await this.$api.user.getUserInfo()
        console.log(res.data)
		    this.$store.commit('setUserInfoDetail',res.data)
        uni.setStorageSync('userInfoDetail',res.data)
        uni.switchTab({
          url: '/pages/index/index'
        })

		  }catch(e){
        uni.switchTab({
          url: '/pages/index/index'
        })
		    //TODO handle the exception
		  }
    }

  }
}